const $login = require('../index')
import memberState from '@src/store/member'

Component({
  properties: {
    options: {
      type: Object
    }
  },
  data: {
    webviewUrl: "",
  },
  observers: {
    'options': function () {
      if (this.data.options && this.data.options.loginParams) {
        let loginParams = JSON.parse(this.data.options.loginParams);
        this.setData({
          "webViewUrl": decodeURIComponent(loginParams.webViewUrl)
        });
      }
    }
  },
  lifetimes: {
    ready: function () {
      if (this.data.options && this.data.options.loginParams) {
        let loginParams = JSON.parse(this.data.options.loginParams);
        this.setData({
          "webViewUrl": decodeURIComponent(loginParams.webViewUrl)
        })
        console.log(JSON.stringify(decodeURIComponent(loginParams.webViewUrl)))
      }
    },
  },
  methods: {
    handleMsg(e) {
      console.info("handleMsg", e)
      if (e.detail.data[0].token.token) {
        $login.setToken(e.detail.data[0].token.token, e.detail.data[0].token.expireTime);
        $login.setAnon(false, e.detail.data[0].token.expireTime);
        memberState.initBase();
      }
    }
  }
})
